define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'secgoods/sec_goods/index' + location.search,
                    add_url: 'secgoods/sec_goods/add',
                    edit_url: 'secgoods/sec_goods/edit',
                    del_url: 'secgoods/sec_goods/del',
                    multi_url: 'secgoods/sec_goods/multi',
                    import_url: 'secgoods/sec_goods/import',
                    table: 'sec_goods',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'class.title', title: __('Class_id')},
                        {field: 'users.nickname', title: __('Users_id')},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'video_files', title: __('Video_files'), operate: false, formatter: Table.api.formatter.files},
                        // {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
                        // {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1')}, formatter: Table.api.formatter.normal},
                        {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'wx_code', title: __('Wx_code'), operate: 'LIKE'},
                        {field: 'qq_code', title: __('Qq_code'), operate: 'LIKE'},
                        {field: 'whats_code', title: __('Whats_code'), operate: 'LIKE'},
                        {field: 'like', title: __('Like')},
                        {field: 'collect', title: __('Collect')},
                        {field: 'want', title: __('Want')},
                        {field: 'browse', title: __('Browse')},
                        {field: 'comment', title: __('Comment')},
                        {field: 'is_sale', title: __('Is_sale'), searchList: {"0":__('Is_sale 0'),"1":__('Is_sale 1')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
